/*
https://www.nowcoder.com/practice/9f3231a991af4f55b95579b44b7a01ba?tpId=13&tqId=23269&ru=/ta/coding-interviews&qru=/ta/coding-interviews/question-ranking
*/

int minNumberInRotateArray(int* nums, int numsLen ) {
    int left = 0, right = numsLen - 1;
    while(left < right){
        int mid = (left + right)/2;
        if(nums[mid] > nums[right]){
            left = mid + 1;
        }
        else if(nums[mid] == nums[right]){
            right--;
        }
        else {
            right = mid;
        }
    }
    return nums[left];
}

/*
我的错误代码
int minNumberInRotateArray(int* nums, int numsLen ) {
    int left = 0, right = numsLen - 1;
    int mid = 0;
    while(left <= right)
    {
        mid = (left + right)/2;
        if(nums[mid] < nums[0])
        {
            right--;
        }
        else
        {
            left++;
        }
    }
    if(nums[mid] < nums[0])
        return nums[mid];
    else
        return nums[0];
}
*/